package algorithm.leetcode.online.q3longestsubstringwithoutrepeatchar;

//Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
public class LongestSubNum {
  public static void main(String[] args){
    String a = "inprobabilitytheoryandstatisticsamedianisdescribedasthenumericvalueseparatingA";
    System.out.println(longestsubnum(a));

  }
  public static int longestsubnum(String a){
    int result = 0, tempresult;
    boolean[] letters = new boolean[256];
    if(a.length() == 1) return 1;
    for(int i = 0; i< a.length()-1; i++){
      for(int k = 0; k < letters.length; k++){
        letters[k] = false;
      }
      letters[a.charAt(i)] = true;
      tempresult = 1;
      for(int j = i+1; j< a.length(); j++){
        if(letters[a.charAt(j)] == true){
          break;
        }else{
          tempresult++;
          letters[a.charAt(j)] = true;
        }
      }
      if(result < tempresult){
        result = tempresult;
      }
    }


    return result;


  }
}
